<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<script type="text/javascript">
<!--
var arr_message = new Array();
var message_cnt = 0;
var auto_recive_message = false;
$(function(){	
	$('#replyModal_uid').val(user.u_id);
	var fm_reply_op = {
		url: 'mircblog/MessageReply_reply',	// 
		dataType: 'text',
		beforeSubmit: function(formData, jqForm, options){
			//alert(formData.form.U_ID);
			var msg = $('#txtreply').val();
			if (msg==''){
				Pub_alert_before('alert', '警告', '写点什么吧.', $('#fm_reply'));
				return false;
			}
			return true;
		},
		success: function(data, statusText){		
			data = eval('('+data+')');			
			if (data.success){				
				MessageReplyDWR.send(data.msg);
				var vumr = data.children[0];
				
				var div = $('#dshowreply'+vumr.VUMR_M_ID);
				var html = '';
				html = showReply(vumr);
				div.prepend(html);
				
				$('#txtreply').val('');
				$('#replyModal').modal('hide');
			} else {
				Pub_alert('alert alert-error', '错误', data.msg, $('#regist_alert'));
			}			
		}
	};	
	$('#fm_reply').ajaxForm(fm_reply_op);
	
	$.post('mircblog/Message_showMessages?form.start=0&form.pagesize=5', function(data){
		data = eval('('+data+')');
		if (data.success){
			var messages = data.children;
			var len = messages.length;			
			for (var i=0;i<len;i++){
				var e = messages[i];
				$('#msgcontent').append(showMessage(e,i+1));
			}			
		} else {
			alert(data.msg);				
		}		
	});  
});

function receiveMessage(data){	
	data = eval('('+data+')');
	if (data.success) {
		message_cnt = message_cnt + 1;
		serverpush_alert('alert alert-info','成功接收','接收了 ' + message_cnt + ' 条消息', $('#ppushmsg'));
	} else {
		serverpush_alert('alert','错误','错误', $('#ppushmsg'));
	}
}

function clkPushMsg(){	
	var url = "mircblog/Message_recive";
	$.post(url, function(result){
		result = eval('('+result+')');
		if (result.success){
			var objs = result.children;
			var s_html = '';//$('#msgcontent').html();
			var i;
			for(i=0;i<objs.length;i++){
				var obj = objs[i];				
				s_html = showMessage(obj,-1) + s_html;
			}
			message_cnt = 0;
			$('#msgcontent').prepend(s_html);				
		} else {
		}
		$('#ppushmsg').html('');
	});			
}

function showMessage(obj,idx){
	var s = '';
	
	s = s + '<div align="left" class="well" >\n';
	if (idx>0)
	s = s + '<span class="badge badge-info">'+idx+'</span>';
	else
		s = s + '<span class="badge badge-warn">.O.</span>';	
  	// userinf beg  	
  	s = s + '<a id="element" class="user" href="#" rel="popover" animation="true"\n';
  	s = s + 'data-content="And here\'s some amazing content. It\'s very engaging. right?"\n';		// 个人简介
  	s = s + 'data-original-title="Ryan Seacrest">\n';														// 昵称
  	s = s + '<img src="images/person_head.jpg" />\n';												// 头像位置
	s = s + '<strong>' + obj.VUMM_U_NICKNAME + ':</strong>';														// 昵称
  	s = s + '</a>\n';
  	// userinf end
  	s = s + '<span>在 <font color="red">' + obj.VUMM_M_DATE + '</font> 的时候发表了如下信息</span>';
  	/*// @ somebody beg   	
	s = s + '<a><span><s>@</s><b>RyanSeacrest</b></span></a>\n';										// @关注人
	s = s + '<a><span><s>@</s><b>Tom</b></span></a>';
	s = s + '<a><span><s>@</s><b>Jack</b></span></a>';
	// @ somebody end*/
	// message beg 
	s = s + '<p align="center">' + obj.VUMM_M_CONTENT + '</p>\n';
	// message end 
	// cmd beg 
	s = s + '<div>\n';
	s = s + '<div class="span1"><a id="aexpand'+obj.VUMM_M_ID+'" href="javascript:void(0);" class="expand-action-wrapper" onclick="clkExpand('+obj.VUMM_M_ID+')">展开</a></div>';
	s = s + '<div class="span5">\n'
	s = s + '<a class="with-icn js-action-reply" data-modal="tweet-reply" href="javascript:void(0);" title="回复" onclick="clkOpenReply('+obj.VUMM_M_ID+', \''+obj.VUMM_U_NICKNAME+'\', -1)">\n';		// 回复href
    s = s + '<i class="icon-share-alt"></i><b>回复</b>\n';
    s = s + '</a>\n';
	s = s + '<a class="with-icn js-toggle-rt" data-modal="tweet-retweet" href="#">\n';
    s = s + '<i class="icon-retweet"></i>\n';
	s = s + '<b><span class="undo-retweet" title="撤销转推">已转推</span>\n';		// 转发id
	s = s + '<span class="retweet" title="转推">转推</span></b>\n';
	s = s + '</a>\n';
    s = s + '<a class="with-icn js-toggle-fav" href="#">\n';						// 收藏/撤销id，      				      				
	s = s + '<b><span class="unfavorite" title="撤销收藏">\n';
    s = s + '<i class="icon-star"></i>已收藏</span>\n';        			
	s = s + '<span class="favorite" title="收藏">\n';
	s = s + '<i class="icon-star-empty"></i>收藏</span></b>\n';
	s = s + '</a>\n';
	s = s + '</div>\n';	
	s = s + '<br/><hr/>';
	s = s + '<div id="dshowreply'+obj.VUMM_M_ID+'" class="control-group"></div>';
	s = s + '</div>\n';
	// cmd end	    			
  	s = s + '</div>\n';
  	//  	
  	return s;	
}

//打开回复的对话框
function clkOpenReply(msgid, username, nowid){
	$('#replyModal_span_username').text(username);
	$('#replyModal_msgid').val(msgid);
	$('#replyModal_nowid').val(nowid);
//	$('#lessLen-reply').text('');
//	$('#txtreply').val('');
	$('#replyModal').modal('show');
}

function showReply(vumr){
	var date = vumr.VUMR_MR_DATE;
	var username = vumr.VUMR_U_NICKNAME;
	var msg = vumr.VUMR_MR_MSG;
	var msgid = vumr.VUMR_M_ID;
	var nowid = vumr.VUMR_MR_ID;
	//msg = '&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp' + msg;
	var html = '<table>';
	html = html + '<tr><td>';
  	html = html + '<a id="element" class="user" href="#" rel="popover" animation="true"\n';
  	html = html + 'data-content="And here\'s some amazing content. It\'s very engaging. right?"\n';
  	html = html + 'data-original-title="Ryan Seacrest">\n';
  	html = html + '<img class="img-circle"  src="images/person_head.jpg" />\n';
  	html = html + '<strong align="top">' + username + '</strong>';
  	html = html + '</a>\n';  	
  	html = html + '</td><td>回复时间'+'2011 11 11';  	
  	html = html + '<a class="with-icn js-action-reply" data-modal="tweet-reply" href="javascript:void(0);" title="回复" onclick="clkOpenReply('+msgid+',\''+username+'\','+nowid+')">\n';
  	html = html + '<i class="icon-share-alt"></i><b>回复</b></a>';
  	html = html + '</td></tr>';
  	html = html + '<tr><td></td><td>';  	
  	html = html + '<div class="box">\n';
  	html = html + '<label class="alert alert-info" style="height:40px;">'+msg+'</label>\n';//
  	html = html + '<div class="triangle" ></div>\n';
  	html = html + '</div>\n';	// class box end
  	html = html + '</td></tr>\n';
  	html = html + '</table>';
  	return html;
}


function clkExpand(msgid){
	var div = $('#aexpand'+msgid);
	var sExpand = '展开';
	var sLess = '收起';
	var dshowreply = $('#dshowreply'+msgid);
	
	if (sExpand==div.text()){
		div.text(sLess);		
			
	} else {
		div.text(sExpand);
		dshowreply.html('');
	}	
}

function clkModalSubmit(){
	$('#fm_reply').submit();	
}
//-->
</script>
<div class="well">

  <h2 align="left">
    <span class="content-header-buttons js-header-button-container"></span>        
    <span class="js-stream-title">发布</span>&nbsp;<small class="view-toggler js-view-toggler"></small>
  </h2>
  <h4 id="ppushmsg" onclick="clkPushMsg()"></h4>
    
  <!-- content beg 这里显示所有消息内容-->  
  	<div id="msgcontent" class="easyui-panel">
  	</div>
<!-- content end -->
</div>

<div class="modal hide fade" id="replyModal">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h3>回复 <span id="replyModal_span_username"></span>的消息</h3>
	</div>
	<div class="modal-body">
		<form id="fm_reply" class="well">
			<span id="lessLen-reply"></span>			
			<input type="hidden" id="replyModal_uid" name="form.MR_U_ID" />
			<input type="hidden" id="replyModal_msgid" name="form.MR_M_ID"/>
			<input type="hidden" id="replyModal_nowid" name="form.MR_R_ID"/>
			<!-- p><input id="txtreply" type="text" style="width:450px" class="input-medium" placeholder="也跟着说点吧..." /></p -->
			<textarea id="txtreply" name="form.MR_MSG" class="twitter-anywhere-tweet-box-editor" 
			style="width: 80%; overflow-x: hidden; overflow-y: hidden; height: 55px; padding-bottom: 5px; " 
			dir="ltr" placeholder="说点自己的idea..." 
			onkeydown="return changebyte('txtreply',50, 'lessLen-reply')" 
			onkeyup="return changebyte('txtreply',50, 'lessLen-reply')"></textarea>		
		</form>
	</div>
	<div class="modal-footer">				
		<a href="javascript:void(0);" class="btn btn-primary" onclick="clkModalSubmit()" >提交</a>
	</div>
</div>
